package J20250330_real;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 类斐波那契循环数——https://www.lanqiao.cn/problems/19699/learning/?page=1&first_category_id=1&name=%E7%B1%BB%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91
 * User: 王圆豪
 * Date: 2025-04-04
 * Time: 21:46
 */
public class Main7 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ret = 0;
        for(int i = 0; i < 1e7; i++){
            if(func(i)){
                ret = Math.max(ret,i);
            }
        }
        System.out.println(ret);
        sc.close();
    }

    static boolean func(int num){
        int layer = 0;
        int tmp = num;
        List<Integer> l = new ArrayList<>();
        while(tmp != 0){
            layer++;
            int cur = tmp%10;
            l.add(cur);
            tmp/=10;
        }
        Collections.reverse(l);
        int p = 0;
        while (true){
            int k = 0;
            for(int i = p; i < p+layer; i++){
                k += l.get(i);
            }
            if(k == num) return true;
            else if(k > num) return false;
            l.add(k);
            p++;
        }
    }
}
